package com.pfzy.lib.sdk.utils;

import android.content.Context;

import java.lang.reflect.Method;

public final class Common {
    private static Context CONTEXT_INSTANCE;

    public static void setContext(Context context) {
        CONTEXT_INSTANCE = context;
    }

    public static Context getContext() {
        if (CONTEXT_INSTANCE == null) {
            synchronized (Common.class) {
                if (CONTEXT_INSTANCE == null) {
                    try {
                        Class<?> ActivityThread = Class.forName("android.app.ActivityThread");
                        Method method = ActivityThread.getMethod("currentActivityThread");
                        Object currentActivityThread = method.invoke(ActivityThread);
                        Method method2 = currentActivityThread.getClass().getMethod("getApplication");
                        CONTEXT_INSTANCE = (Context) method2.invoke(currentActivityThread);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return CONTEXT_INSTANCE;
    }
}
